<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
    /* 自定义表格样式 */
    table {
      overflow-x: auto;
      width: 100%;
      border-collapse: collapse;
      margin: 2px 0;
      box-shadow: 0 0 9px rgba(0, 0, 0, 0.1);
    }

    td {
      font-size: 13px;
      padding: 1px 1px;
      text-align: left;
    }

    th {
      font-size: 15px;
      padding: 1px 1px;
      text-align: left;
      border-bottom: 1px solid #ddd;
      background-color: #f4f4f9;
      color: #333;
      font-weight: 3;
    }

    tr:hover {
      background-color: #f9f9f9;
      transition: background-color 0.3s ease;
    }

    tr:nth-child(even) {
      background-color: #fafafa;
    }

    /* 添加边框 */
    table,
    th,
    td {
      border: 1px solid #e0e0e0;
    }
  </style>
</head>
<script type="application/javascript">
  function checkTableColumnConsistency(tableId, columnIndex) {
    const table = document.getElementById(tableId);
    const rows = Array.from(table.getElementsByTagName('tr'));

    // 提取第一行的值作为基准
    const firstRow = rows[0];
    const firstCell = firstRow.cells[columnIndex];
    const firstValue = firstCell.textContent.trim(); // 去除空格

    // 比较后续行的值是否一致
    let isConsistent = true;
    let inconsistentRows = [];

    for (let i = 1; i < rows.length; i++) {
      const currentRow = rows[i];
      const currentCell = currentRow.cells[columnIndex];
      const currentValue = currentCell.textContent.trim(); // 去除空格

      // 比较值是否一致
      if (currentValue !== firstValue) {
        isConsistent = false;
        inconsistentRows.push({
          rowIndex: i + 1, // 行号从1开始计数
          value: currentValue
        });
      }
    }

    // 如果值不一致，弹框提示
    if (!isConsistent) {
      const message = `表格中第 ${columnIndex + 1} 列的值不一致！\n` +
              `第 ${inconsistentRows.map(row => row.rowIndex).join(', ')} 行的值为 ${inconsistentRows.map(row => row.value).join(', ')}，而基准值为 ${firstValue}。\n` +
              `请检查这些行的值是否正确。`;
      alert(message);
    } else {
      console.log(`表格中第 ${columnIndex + 1} 列的值一致，均为 ${firstValue}。`);
    }
  }


</script>
<body>
<div>
  <table id="myTable">
    <tr>
      <td>A</td>
      <td>1</td>
    </tr>
    <tr>
      <td>B</td>
      <td>2</td>
    </tr>
    <tr>
      <td>C</td>
      <td>3</td>
    </tr>
    <!-- 其他行 -->
  </table>
  <button onclick="checkTableColumnConsistency('myTable', '0')"> 点击按钮 </button>
</div>
</body>
</html>